package com.bydq.patrolsystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bydq.patrolsystem.entity.PsInspectiontaskDetail;
import com.bydq.patrolsystem.service.PsInspectiontaskDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("statistics")
public class StatisticsController {

    @Autowired
    private PsInspectiontaskDetailService psInspectiontaskDetailService;

    @RequestMapping("/inspectiontask")
    public String inspectiontask(Model m){
        m.addAttribute("type","inspectiontask");
        return "statistics";
    }

    @RequestMapping("/wipe")
    public String wipe(Model m){
        m.addAttribute("type","wipe");
        return "statistics";
    }

    @ResponseBody
    @RequestMapping("/getIs")
    public Map<String,Object> getis(Integer page, Integer limit,Integer taskId, String lineCode, Integer isBug){

        page=page==null?1:page;
        limit=limit==null?5:limit;

        IPage<PsInspectiontaskDetail> p=new Page<>(page,limit);

        QueryWrapper<PsInspectiontaskDetail> qw=new QueryWrapper<>();
        qw.eq(taskId!=null,"taskId",taskId);
        qw.like(lineCode!=null,"lineCode",lineCode);
        qw.eq(isBug!=null,"isBug",isBug);

        psInspectiontaskDetailService.page(p,qw);

        Map<String,Object> map=new HashMap<String,Object>();
        map.put("code",0);
        map.put("count",p.getTotal());
        map.put("data",p.getRecords());

        return map;
    }
}
